package org.bulu.project.system.service.impl.per;

import org.bulu.project.system.mapper.FavoriteMapper;
import org.bulu.project.system.mapper.FavoriteVideoMapper;
import org.bulu.project.system.model.entity.Favorite;
import org.bulu.project.system.model.entity.FavoriteVideo;
import org.bulu.project.system.service.FavoriteVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Set;

@Service
public class FavoriteVideoServiceImpl implements FavoriteVideoService {
    @Autowired
    private FavoriteVideoMapper favoriteVideoMapper;
    //根据fid查询收藏夹中视频vid集合
    @Override
    public List<Integer> findFidsOfCollected(Integer fid) {
        return favoriteVideoMapper.getVidList(fid);
    }

    //添加视频到收藏夹
    @Override
    public void addToFav(Integer uid, Integer vid, Integer fid) {
        FavoriteVideo favoriteVideo = new FavoriteVideo();
        favoriteVideo.setFid(fid);
        favoriteVideo.setVid(vid);
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        favoriteVideo.setTime(date);
        favoriteVideo.setIsRemove(null);
        favoriteVideoMapper.insert(favoriteVideo);
    }

    @Override
    public void removeFromFav(Integer uid, Integer vid, Integer fid) {
        FavoriteVideo favoriteVideo = new FavoriteVideo();
        favoriteVideo.setFid(fid);
        favoriteVideo.setVid(vid);
        favoriteVideoMapper.deleteById(favoriteVideoMapper.queryAllByLimit(favoriteVideo).getId());
    }


}
